﻿Imports System.Data.SqlClient

Public Class column_default
    Inherits System.Web.UI.Page
    Dim objrd As SqlDataReader = Nothing
    Dim objdt As New GetData
    Dim strErr As String = ""
    Dim ps As New PreparedStatement(sSQL)
    Dim sSQL As String
    Private i As Integer
    Private pages As Integer
    Private objfind As New GetData
    Private pss As New PreparedStatement(sSQL)
    Private objrds As SqlDataReader = Nothing

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim strCat As String = ""
        Dim strCol As String = ""
        ps.strSql = "select * from Category where lang_flag='en'order by category_name"
        Dim conn As SqlConnection = objdt.getConn()

        objrd = objdt.dr(ps, strErr, conn, objrd)

        While (objrd.Read())
            strCat &= "<li><a href=""category_default.aspx?cid=" & objrd.Item("category_id") & """>" & objrd.Item("category_name") & "</a></li>"
        End While
        categorylist.InnerHtml = strCat
        ps.strSql = "select * from Columns where lang_flag='en'order by Column_Name"
        objrd = objdt.dr(ps, strErr, conn, objrd)
        While (objrd.Read())
            strCol &= "<li><a href=""column_default.aspx?aid=" & objrd.Item("Column_ID") & """>" & objrd.Item("Column_Name") & "</a></li>"
        End While


        columnlist.InnerHtml = strCol

        Dim columnId As String

        Dim strSql As String = ""
        Dim sum, sumdesc As Integer


        i = Request("page")
        If i = Nothing Or i = 0 Then
            i = 1

        End If
        columnId = Request("aid")
        strErr = ""
        sSQL = "select count(*) from Column_New where Column_ID<>0"
        If (Request("aid") <> Nothing And Request("aid") <> "") Then
            strSql = " and Column_ID =@columnId"
            ps.addParameter("columnId", columnId)


        End If
        ps.strSql = sSQL + strSql


        objrd = objfind.dr(ps, strErr, conn, objrd)
        objrd.Read()
        sum = objrd.Item(0)
        pages = (sum \ 10) + 1
        If i >= pages Then
            i = pages
        ElseIf i <= 0 Then
            i = 1
        End If
        If (i = pages) Then
            sumdesc = sum
        Else
            sumdesc = i * 10
        End If
        totalPage.InnerText = i.ToString & "/" & pages.ToString()
        sSQL = "select top(" & i & "*10) * from Column_New where Column_ID<>0"
        sSQL += strSql
        sSQL += " and New_ID not in (select top (" & i - 1 & "*10) New_ID from Column_New where Column_ID<>0"
        sSQL += strSql
        sSQL += " order by New_ID) and New_ID not in (select top(" & sum - sumdesc & ") New_ID from Column_New where Column_ID<>0"
        sSQL += strSql
        sSQL += " order by New_ID desc) order by New_ID"
        ps.strSql = sSQL


        objrd = objfind.dr(ps, strErr, conn, objrd)
        purchaseList.InnerHtml = "<table width=""98%"" border=""0"" cellpadding=""5"" cellspacing=""2"" style=""margin-top:10px;"">" & _
                                     "<tr>" & _
                                         "<td bgcolor=""#EEE"">Title</td>" & _
                                         "<td width=""160px"" bgcolor=""#EEE"">Create Date</td>" & _
                                     "</tr>"
        Dim con As SqlConnection = objfind.getConn()

        While (objrd.Read())
            sSQL = "select Column_Name from Columns where Column_ID =@columnId"
            pss.addParameter("columnId", objrd("Column_ID"))
            pss.strSql = sSQL

            objrds = objfind.dr(pss, strErr, con, objrds)
            Dim cName As String = ""
            If objrds.HasRows Then
                objrds.Read()
                currentCol.Text = objrds("Column_Name")
            End If

            purchaseList.InnerHtml += "<tr>" & _
                                        "<td bgcolor=""#F5F5F5""> <a href=""columnlist.aspx?newsId=" & objrd("New_ID") & "&aid=" & objrd("Column_ID") & """ >" & objrd("title") & "</a></td>" & _
                                        "<td bgcolor=""#F5F5F5""> " & objrd("create_date") & "</td>" & _
                                    "</tr>"
        End While
        objfind.closeConn(conn)
        objfind.closeConn(con)
        purchaseList.InnerHtml += "</table>"
        pageNav.InnerHtml = "<a href=""column_default.aspx?page=1" & "&aid=" & Request("aid") & """>home &nbsp;</a>&nbsp;|&nbsp;" & _
                            "<a href=""column_default.aspx?page=" & i - 1 & "&aid=" & Request("aid") & """>previous page &nbsp;</a>&nbsp;|&nbsp;" & _
                            "<a href=""column_default.aspx?page=" & i + 1 & "&aid=" & Request("aid") & """>next page &nbsp;</a>&nbsp;|&nbsp;" & _
                            "<a href=""column_default.aspx?page=" & pages & "&aid=" & Request("aid") & """>end &nbsp;</a>"




    End Sub

End Class